<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<title>提交订单</title>
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/base.css" />
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/mod.css" />
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/list.css" />
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/page.css" />
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/competition.css?v=1" />
		<script src="{$staticHost}/static/js/jquery-1.8.3.min.js"></script>
		<script src="{$staticHost}/static/js/js.js"></script>
		<script src="{$staticHost}/static/js/mod.js"></script>
	</head>
	<body>
		<section id="info-box" class="pb50"></section>
		<script id="info" type="text/html">
			<div class="order-list line-gray-bottom">
				<h2 class="f14 line-gray p10">
					收货信息
					<a id="addren" class="fr color-blue">+增加收货人</a>
				</h2>
	          <%for(var i=0; i<result.consigneeList.length; i++){%>
				<div class="recipients line-gray">
					<a style="display:none" class="delete">删除</a>
					<%=result.consigneeList[i].name%> <span class="pl20"><%=result.consigneeList[i].phone%></span>
					<p>
						<%=result.consigneeList[i].province%>
						<%=result.consigneeList[i].city%>
						<%=result.consigneeList[i].district%>
						<%=result.consigneeList[i].address%>

						<i style="display:none" class="ico-location-blue"></i>
					</p>
	                <span class="addressid" style="display:none"><%=result.consigneeList[i].id%> </span>
				</div>
	          <%}%>
			</div>
			 <p class="line-gray-bottom p10 f14">
				报名费
				<span class="color-blue fr">￥<%=result.cost%></span>
			</p>

			<%if(result.goodsList.length>0){%>
			<ul class="line-gray-bottom order-xq">
				<%for(var i=0; i<result.goodsList.length; i++){%>
				<li class="square-img">
					<img src="<%=result.goodsList[i].product.imageList[0]%>" />
					<ol>
						<li>
							<%=result.goodsList[i].product.title%>
							<span class="color-blue">￥<%=result.goodsList[i].goodsInfo.saleprice%></span>
						</li>
						<li class="pt-10">
							<%=result.subTtitle%>
							<span>X1</span>
						</li>
					</ol>
				</li>
				<%}%>
			</ul>




			<div class="p15 clearfix lh30 line-gray-bottom f16">
				<p>
					运费
					<span class="fr">￥<%=result.shipping_fee%></span>
				</p>
				<p>
					纪念品折扣
					<span class="fr"><%=result.discount%>折</span>
				</p>
				<p class="fr">合计：￥<em class="color-blue"><%=result.price%></em></p>
			</div>

			<%}%>
			<div class="p10 lh34 line-gray-bottom clearfix f16">
				<p>
					应付
					<span class="fr">￥
					<%if(result.goodsList.length>0&&result.discount!=1){%>
						<%=result.price_desc%>
						=
					<%}%>

					<%if(result.goodsList.length>0&&result.discount==1){%>
						<%=result.cost%>
						+
						<%=result.price%> 
						=
					<%}%>
					<%=result.total_fee%>

					</span>
				</p>
				
			</div>

			<div class="btn-apply pa">
				合计：<span class="color-blue">￥<%=result.total_fee%></span>
				<a id="tjdd" class="red">提交订单</a>
			</div>
        </script>
        <div id="forlogin" class="c-mask" style="display: none;overflow:auto;">
	        <section class="pop-up" >
				<span class="close">×</span>
				<div class="consignee-pop"  style="">
					<h1>
						<p>
							<i class="left-line"></i>
							新增收货人
							<i class="right-line"></i>
						</p>
					</h1>
					<div class="inputlist">
						<input id="namea" name="name" placeholder=" 收货人姓名"  type="text" value="" />
						<input id="phonea" name="phone"  onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder=" 手机号码"  type="text" value="" />
						<input id="provincea" placeholder="省份"  type="text" name="province" value="" />
						<input id="citya" placeholder=" 城市"  type="text" name="city" value="" />
						<input id="districta" placeholder=" 区"  type="text" name="district" value="" />
						<input id="addressa" placeholder=" 详细地址"  type="text" name="address" value="" />
						<div class="p15">
							<span>是否设为默认地址:</span>
							<input type="radio" name="is_default" value="是" checked> 是
							<input type="radio" name="is_default" value="否"> 否
						</div>
					</div>
					<input id="addtj" type="submit" value="提交"/>
				</div>
				<!-- 新增收货人 -->
				<div class="failure-pop"style="display: none;">
					<p class="f16">小主，增加地址失败，是咱家房子不拉</p>
				</div>
				<div class="no-pop"style="display: none;">
					<p class="f16"></p>
				</div>
			</section>
		</div>
        <script>
       		var match_id = '{$match_id}'
	        var goods_id = '{$goods_id}'
	        var gid  = '0'
	       
        $(function(){
        	$.getJSON('{$staticHost}/orderWeb/goodsDetail',{"aid":match_id,"atype":"match","goods_id":goods_id}, function(data, error) {
				
				var html = template('info', data);
				document.getElementById('info-box').innerHTML = html;
			
				if(data.result.shipping_fee==0.00){
					$("#yf").html("包邮")
				}
				// 判断有无运费
				var discount = data.result.discount;
				if(discount>=1){
					$("#zc").html("无折扣")
				}else{
					discount = discount*10
					$("#zc").html(discount)
				}	
			
       
           var match = data.result.atype;
           
			$("#tjdd").click(function(){
	        	var consignee_id = $(".bg-cogray").children(".addressid").html();
	        	if(!consignee_id){
					$(".consignee-pop").hide();
	        		$("#forlogin").show();
					$(".failure-pop").html("请选择地址");

					$(".failure-pop").show();
	        		return
	        	}
	        	var params = {"consignee_id":consignee_id,"aid":match_id,"goods_id":goods_id,"gid":gid,"atype":match}
                $.ajax({
                    "url": "{$staticHost}/orderWeb/order",
                    "type": 'POST',
                    "data": params,
                    "dataType": 'json',
                    "success": function(data){
                    	if(data.error){
                    		$(".consignee-pop").hide();
			        		$("#forlogin").show();
							$(".failure-pop").html("error.text");
							$(".failure-pop").show();
							setTimeout(function(){
                    			window.history.back(-1);
                    		},1000);

                    	}
                    	order_id = data.result.order_id;
                        if(data){
                            window.location.href = '{$staticHost}/show/orderPay?order_id='+order_id
                        }else{
                            alert(data.error.text)
                            $(".consignee-pop").hide()
                            $(".failure-pop").show();
                        }
			   	    },
                    "error": function(){
				      	$(".consignee-pop").hide()
				      	$(".failure-pop").show();
                    }
                })
	        })
	        

			$("#addren").click(function(){
	        	$("#forlogin").show();
				$(".consignee-pop").show();
				$(".failure-pop").hide();
			})
	        $(".close").click( function(){
				$("#forlogin").hide();
			});
			$("#addtj").click(function(){
				var namea = $("#namea").val()
				var phonea = $("#phonea").val()
				var provincea = $("#provincea").val()
				var citya = $("#citya").val()
				var districta = $("#districta").val()
				var addressa = $("#addressa").val()
				var is_defaulta = $("input[name='is_default']:checked").val()
				var params = {name:namea,phone:phonea,province:provincea,city:citya,district:districta,address:addressa,is_default:is_defaulta}
				$.post("/orderWeb/consignee",params,
				    function(data,status){
				     data = JSON.parse(data)
				   
				       if(data.result && data.status){
				      	window.location.reload()
				      }else{
				      	$(".consignee-pop").hide()
				      	$(".failure-pop").show();
				      }
			   	 });
			})

			$(".recipients").click(function(){
				$(".recipients a").hide();
			    $(".ico-location-blue").hide()

				$(".recipients").removeClass("bg-cogray");
			    $(this).children(".delete").show()
			    $(this).children("p").children(".ico-location-blue").show()

			    $(this).addClass("bg-cogray");
			});

			$(".delete").click(function(){
				var parent = $(this).parent();
				var id =parent.children(".addressid").html();
				consignee_id =id;
				$.getJSON('{$staticHost}/orderWeb/delConsignee', {"id":id}, function(data, error) {
				if(data.result && data.result.is_success==1){
					parent.remove();
					}
				});
			});


				})
			});
		</script>
	</body>
</html>

